#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: topbar.py
# Author: Tomás Vírseda
# License: GPL v3
# Description:  The menu bar manager class

class MenuManager:
    """ content manager """

    def __init__(self, gui):
        self.gui = gui

        # containers
        self.gui.frontend['menuaddres'] = self.gui.glade.widgets.get_widget("mnuAppAddResource")
        self.gui.frontend['menu'] = self.gui.glade.widgets.get_widget("mnuMainBar")
        self.gui.frontend['mnukbexport'] = self.gui.glade.widgets.get_widget("mnuKBExport")
        self.gui.frontend['mnukbimport'] = self.gui.glade.widgets.get_widget("mnuKBImport")
        self.gui.frontend['mnuabout'] = self.gui.glade.widgets.get_widget("mnuAbout")
        self.gui.frontend['mnustarthere'] = self.gui.glade.widgets.get_widget("mnuAppStartHere")
        self.gui.frontend['mnusearch'] = self.gui.glade.widgets.get_widget("mnuAppSearchResources")
        self.gui.frontend['mnulocal'] = self.gui.glade.widgets.get_widget("mnuAppExploreLocalResources")
        self.gui.frontend['mnuquery'] = self.gui.glade.widgets.get_widget("mnuAppAdvancedQueries")
        self.gui.frontend['mnuprefs'] = self.gui.glade.widgets.get_widget("mnuAppPreferences")
        self.gui.frontend['mnuquit'] = self.gui.glade.widgets.get_widget("mnuAppQuit")

        self.gui.frontend['connections'] = {
            'mnuAppAddResource/activate'    : self.add_new_resource,
            'mnuKBExport/activate'  :   self.kb_export,
            'mnuKBImport/activate'  :   self.kb_import,
            'mnuAbout/activate'     :   self.show_about_dialog,
            'mnuAppStartHere/activate'  :   self.starthere,
            'mnuAppSearchResources/activate'  :   self.nothing,
            'mnuAppExploreLocalResources/activate'  :   self.nothing,
            'mnuAppAdvancedQueries/activate'  :   self.sparqleditor,
            'mnuAppPreferences/activate'  :   self.show_preferences,
            'mnuAppQuit/activate'  :   self.quit_app,
        }

        #connect signals
        for wid_con, func in self.gui.frontend['connections'].iteritems():
            wid,con = wid_con.split('/')
            self.gui.glade[wid].connect(con,func)

    def add_new_resource(self, *args):
        self.gui.actions.add_new_resource()

    def nothing(self, *args):
        pass

    def starthere(self, *args):
        self.gui.actionbar.starthere()

    def sparqleditor(self, *args):
        self.gui.actionbar.queries()

    def kb_export(self, *args):
        self.gui.manager.show_export()

    def kb_import(self, *args):
        self.gui.manager.show_import()

    def show_about_dialog(self, *args):
        self.gui.actions.show_about_dialog()

    def quit_app(self, *args):
        self.gui.actions.stop()

    def show_preferences(self, *args):
        self.gui.actions.show_preferences()
